#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>

void *thmain1(void *arg); // 线程1的主函数

struct st_ret{
    int retcode;        // 返回代码
    char message[1024]; // 返回内容
};

int main(int argc, char *argv[])
{
    pthread_t thid = 0;


    if (pthread_create(&thid, NULL, thmain1, NULL) != 0)
    {
        printf("pthread_create failed.\n");
        exit(-1);
    }

    // 等待子线程退出。
    printf("join...\n");

    // void *pv = 0;
    // pthread_join(thid, &pv);
    // printf("ret=%ld\n", (long)pv);
    struct st_ret *pst = 0;
    pthread_join(thid, (void**)&pst);
    printf("retcode=%d,message=%s\n", pst->retcode, pst->message);
    delete pst;
    
    printf("join ok.\n");
}

void *thmain1(void *arg)
{
    printf("线程开始运行。\n");
    // return 0;
    // return (void*)1;
    // pthread_exit((void*)1150);

    struct  st_ret *ret = new struct st_ret;
    ret->retcode = 1120;
    strcpy(ret->message, "测试返回");
    pthread_exit((void*)ret);
}